package com.kyin.satoken.config;

import cn.dev33.satoken.strategy.SaStrategy;
import cn.hutool.core.map.MapUtil;
import com.kyin.satoken.utils.JwtUtil;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;

@Configuration
public class SaTokenConfigure {
    /**
     * 重写 Sa-Token 框架内部算法策略 
     */
    @PostConstruct
    public void rewriteSaStrategy() {
        // 重写 Token 生成策略 
        SaStrategy.instance.createToken = (loginId, loginType) -> {
            Map<String, Object> claims = MapUtil.newHashMap();
            claims.put("loginId", loginId);
            claims.put("loginType", loginType);
            return JwtUtil.generateToken(claims, loginId.toString());
        };
    }
}
